{
                match (left, right) {
                    (BasicValueEnum::IntValue(l), BasicValueEnum::IntValue(r)) => {
                        // Ensure both operands have the same type
                        let (l_casted, r_casted) = if l.get_type() != r.get_type() {
                            // Cast to the wider type
                            if l.get_type().get_bit_width() > r.get_type().get_bit_width() {
                                let r_ext = self.builder.build_int_z_extend_or_bit_cast(
                                    r,
                                    l.get_type(),
                                    "r_cast",
                                )?;
                                (l, r_ext)
                            } else {
                                let l_ext = self.builder.build_int_z_extend_or_bit_cast(
                                    l,
                                    r.get_type(),
                                    "l_cast",
                                )?;
                                (l_ext, r)
                            }
                        } else {
                            (l, r)
                        };
                        let result = self.builder.build_int_compare(
                            inkwell::IntPredicate::NE,
                            l_casted,
                            r_casted,
                            "neq",
                        )?;
                        // Convert i1 to i32
                        Ok(self
                            .builder
                            .build_int_z_extend(result, self.context.i32_type(), "neq_ext")?
                            .into())
                    }
                    (BasicValueEnum::FloatValue(l), BasicValueEnum::FloatValue(r)) => {
                        // Ensure both operands have the same type
                        let (l_casted, r_casted) = if l.get_type() != r.get_type() {
                            // Cast to the wider type (f64)
                            // f64 has more bits than f32
                            if l.get_type() == self.context.f32_type()
                                && r.get_type() == self.context.f64_type()
                            {
                                let l_ext = self.builder.build_float_ext(
                                    l,
                                    self.context.f64_type(),
                                    "l_cast",
                                )?;
                                (l_ext, r)
                            } else if l.get_type() == self.context.f64_type()
                                && r.get_type() == self.context.f32_type()
                            {
                                let r_ext = self.builder.build_float_ext(
                                    r,
                                    self.context.f64_type(),
                                    "r_cast",
                                )?;
                                (l, r_ext)
                            } else {
                                // Default: cast right to left's type
                                let r_ext =
                                    self.builder.build_float_cast(r, l.get_type(), "r_cast")?;
                                (l, r_ext)
                            }
                        } else {
                            (l, r)
                        };
                        let result = self.builder.build_float_compare(
                            inkwell::FloatPredicate::ONE,
                            l_casted,
                            r_casted,
                            "fneq",
                        )?;
                        // Convert i1 to i32
                        Ok(self
                            .builder
                            .build_int_z_extend(result, self.context.i32_type(), "fneq_ext")?
                            .into())
                    }
                    (BasicValueEnum::PointerValue(l), BasicValueEnum::PointerValue(r)) => {
                        // Check if both operands are strings (i8*)
                        let left_val = l.into();
                        let right_val = r.into();
                        if self.is_string_type(&left_val) && self.is_string_type(&right_val) {
                            // String content comparison using strcmp
                            // For !=, we want the opposite of ==
                            let eq_result =
                                self.generate_string_content_compare(left_val, right_val)?;
                            let one = self.context.i32_type().const_int(1, false);
                            let result = self.builder.build_int_compare(
                                inkwell::IntPredicate::EQ,
                                eq_result.into_int_value(),
                                one,
                                "string_neq",
                            )?;
                            // Convert i1 to i32: 1 if not equal, 0 if equal
                            let zero = self.context.i32_type().const_int(0, false);
                            let one_i32 = self.context.i32_type().const_int(1, false);
                            Ok(self
                                .builder
                                .build_select(result, zero, one_i32, "string_neq_result")?
                                .into())
                        } else {
                            // Pointer comparison (including rc<T> and weak<T>)
                            let result = self.builder.build_int_compare(
                                inkwell::IntPredicate::NE,
                                l,
                                r,
                                "ptr_neq",
                            )?;
                            // Convert i1 to i32
                            Ok(self
                                .builder
                                .build_int_z_extend(result, self.context.i32_type(), "ptr_neq_ext")?
                                .into())
                        }
                    }
                    (BasicValueEnum::StructValue(l), BasicValueEnum::StructValue(r)) => {
                        let l_type = l.get_type();
                        let r_type = r.get_type();
                        if self.is_trait_handle_struct_type(l_type)
                            && self.is_trait_handle_struct_type(r_type)
                        {
                            let l_data = self
                                .builder
                                .build_extract_value(l, 0, "trait_handle_l_data")?
                                .into_pointer_value();
                            let l_meta = self
                                .builder
                                .build_extract_value(l, 1, "trait_handle_l_meta")?
                                .into_pointer_value();
                            let r_data = self
                                .builder
                                .build_extract_value(r, 0, "trait_handle_r_data")?
                                .into_pointer_value();
                            let r_meta = self
                                .builder
                                .build_extract_value(r, 1, "trait_handle_r_meta")?
                                .into_pointer_value();
                            let data_eq = self.builder.build_int_compare(
                                inkwell::IntPredicate::EQ,
                                l_data,
                                r_data,
                                "trait_handle_data_eq",
                            )?;
                            let meta_eq = self.builder.build_int_compare(
                                inkwell::IntPredicate::EQ,
                                l_meta,
                                r_meta,
                                "trait_handle_meta_eq",
                            )?;
                            let combined = self
                                .builder
                                .build_and(data_eq, meta_eq, "trait_handle_eq")?;
                            let inverted =
                                self.builder
                                    .build_not(combined, "trait_handle_ne_bool")?;
                            Ok(self
                                .builder
                                .build_int_z_extend(
                                    inverted,
                                    self.context.i32_type(),
                                    "trait_handle_ne_ext",
                                )?
                                .into())
                        } else {
                            Err(CompilerError::internal("Type mismatch in comparison"))
                        }
                    }
                    (BasicValueEnum::PointerValue(ptr), BasicValueEnum::IntValue(int))
                    | (BasicValueEnum::IntValue(int), BasicValueEnum::PointerValue(ptr)) => {
                        let ptr_as_int =
                            self.builder
                                .build_ptr_to_int(ptr, int.get_type(), "ptr_to_int")?;
                        let result = self.builder.build_int_compare(
                            inkwell::IntPredicate::NE,
                            ptr_as_int,
                            int,
                            "ptr_int_neq",
                        )?;
                        Ok(self
                            .builder
                            .build_int_z_extend(result, self.context.i32_type(), "ptr_int_neq_ext")?
                            .into())
                    }
                    (l, r) => Err(CompilerError::internal(&format!(
                        "Type mismatch in comparison: {:?} vs {:?}",
                        l.get_type(),
                        r.get_type()
                    ))),
                }
            }
